package com.ktgj.other.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.other.domain.EtOrderPaymentrecord;
import com.ktgj.other.domain.vo.RefundProgressVo;
import com.ktgj.other.mapper.EtOrderPaymentrecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.other.mapper.EtOrderTrackMapper;
import com.ktgj.other.domain.EtOrderTrack;
import com.ktgj.other.service.IEtOrderTrackService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@Service
public class EtOrderTrackServiceImpl implements IEtOrderTrackService 
{
    @Autowired
    private EtOrderTrackMapper etOrderTrackMapper;
    @Autowired
    private EtOrderPaymentrecordMapper etOrderPaymentrecordMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param traceid 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public EtOrderTrack selectEtOrderTrackById(Long traceid)
    {
        return etOrderTrackMapper.selectEtOrderTrackById(traceid);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param etOrderTrack 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<EtOrderTrack> selectEtOrderTrackList(EtOrderTrack etOrderTrack)
    {
        return etOrderTrackMapper.selectEtOrderTrackList(etOrderTrack);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param etOrderTrack 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertEtOrderTrack(EtOrderTrack etOrderTrack)
    {
        return etOrderTrackMapper.insertEtOrderTrack(etOrderTrack);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param etOrderTrack 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateEtOrderTrack(EtOrderTrack etOrderTrack)
    {
        return etOrderTrackMapper.updateEtOrderTrack(etOrderTrack);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param traceids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteEtOrderTrackByIds(Long[] traceids)
    {
        return etOrderTrackMapper.deleteEtOrderTrackByIds(traceids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param traceid 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteEtOrderTrackById(Long traceid)
    {
        return etOrderTrackMapper.deleteEtOrderTrackById(traceid);
    }

    /**
     * 退款进度
     * */
    @Override
    public RefundProgressVo refundProgress(Long id) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        RefundProgressVo refundProgressVo = new RefundProgressVo();

        EtOrderPaymentrecord etOrderPaymentrecord = etOrderPaymentrecordMapper.orderPaymentrecord(id);
        if (etOrderPaymentrecord.getPaymenttype().equals(EmHelper.cardType.CREDIT_CARD.getValue())){
            refundProgressVo.setPayType("信用卡");
        }
        else if (etOrderPaymentrecord.getPaymenttype().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
            refundProgressVo.setPayType("借记卡");
        }
        else if (etOrderPaymentrecord.getPaymenttype().equals(EmHelper.cardType.UnionPayQR.getValue())){
            refundProgressVo.setPayType("银联二维码");
        }
        else if (etOrderPaymentrecord.getPaymenttype().equals(EmHelper.cardType.Voice.getValue())){
            refundProgressVo.setPayType("语音");
        }
        else if (etOrderPaymentrecord.getPaymenttype().equals(EmHelper.cardType.Applets.getValue())){
            refundProgressVo.setPayType("微信小程序");
        }

        List<EtOrderTrack> etOrderTrackList = etOrderTrackMapper.orderTrackList(id);
        refundProgressVo.setTime(format.format(etOrderTrackList.get(0).getCreateTime()));
        if (etOrderTrackList != null && etOrderTrackList.size() > 0){
            for (EtOrderTrack etOrderTrack : etOrderTrackList) {
                etOrderTrack.setTime(format.format(etOrderTrack.getCreateTime()));
            }
        }
        refundProgressVo.setEtOrderTrackList(etOrderTrackList);
        return refundProgressVo;
    }
}
